//
//  Util.h
//  EncryptionTPB
//
//  Created by LvJianfeng on 15/9/15.®
//  Copyright © 2015年 coderjianfeng@foxmail.com. All rights reserved.
//
//
//    ________           .___ __________.__                         _____.___.
//   /  _____/  ____   __| _/ \______   \  |   ____   ______ ______ \__  |   | ____  __ __
//  /   \  ___ /  _ \ / __ |   |    |  _/  | _/ __ \ /  ___//  ___/  /   |   |/  _ \|  |  \
//  \    \_\  (  <_> ) /_/ |   |    |   \  |_\  ___/ \___ \ \___ \   \____   (  <_> )  |  /
//   \______  /\____/\____ |   |______  /____/\___  >____  >____  >  / ______|\____/|____/
//          \/            \/          \/          \/     \/     \/   \/
//
//
#define LOGOPEN 1
#define VC_LOGOPEN 1
#define DB_BLOCK_LOG
#define NET_BLOCK_LOG 1

#pragma mark ---- AppDelegate
//AppDelegate
#define APPDELEGATE [(AppDelegate*)[UIApplication sharedApplication] delegate]

//UIApplication
#define APPD [UIApplication sharedApplication]
#define rootNavVC (UINavigationController*)[[[[UIApplication sharedApplication] delegate] window] rootViewController]

#pragma mark ---- UIImage UIImageView functions
#define IMG(name) [UIImage imageNamed:name]

#pragma mark ---- File functions
#define PATH_OF_APP_HOME NSHomeDirectory()
#define PATH_OF_TEMP NSTemporaryDirectory()
#define PATH_OF_DOCUMENT [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

#pragma mark ---- String  functions
#define EMPTY_STRING        @""
#define STR(key)            NSLocalizedString(key, nil)

#pragma mark ---- String null
#define isNullString(X)  (X==nil || X==(NSString *)[NSNull null] || [X length]==0)

#pragma mark ---- color functions
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]

#pragma mark ----Size ,X,Y, View ,Frame
//get the size of the Screen
#define SCREEN_HEIGHT [[UIScreen mainScreen]bounds].size.height
#define SCREEN_WIDTH [[UIScreen mainScreen]bounds].size.width

//get the size of the Application
#define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height
#define APP_WIDTH [[UIScreen mainScreen]applicationFrame].size.width

//get the left top origin's x,y of a view
#define VIEW_TX(view) (view.frame.origin.x)
#define VIEW_TY(view) (view.frame.origin.y)

//get the width size of the view:width,height
#define VIEW_W(view) (view.frame.size.width)
#define VIEW_H(view) (view.frame.size.height)

#pragma mark ---log  flag
#define LogFrame(frame) NSLog(@"frame[X=%.1f,Y=%.1f,W=%.1f,H=%.1f",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height)
#define LogPoint(point) NSLog(@"Point[X=%.1f,Y=%.1f]",point.x,point.y)

#if LOGOPEN
#define DDDLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define DDDLog(FORMAT, ...)
#endif

//viewController log
#ifdef VC_LOGOPEN
#define LogVC DDDLog
#else
#define LogVC
#endif

//dbbase log
#ifdef DB_BLOCK_LOG
#define LogDB DDDLog
#else
#define LogDB
#endif


//networking log
#if NET_BLOCK_LOG
#define LogNET DDDLog
#else
#define LogNET
#endif

//view log
#ifdef VIEW_BLOCK_LOG
#define LogVIEW DDDLog
#else
#define LogVIEW
#endif

#import <Foundation/Foundation.h>
#import "MBProgressHUD.h"

typedef enum{
    //年开始
    Year = 0,
    YearMonth,
    YearMonthHorizontalLine,
    YearMonthSlash,
    YearMonthPoint,
    YearMonthDay,
    YearMonthDayHorizontalLine,
    YearMonthDaySlash,
    YearMonthDayPoint,
    //月开始
    Month,
    MonthYear,
    MonthYearHorizontalLine,
    MonthYearSlash,
    MonthYearPoint,
    MonthDay,
    MonthDayHorizontalLine,
    MonthDaySlash,
    MonthDayPoint,
    MonthDayYear,
    MonthDayYearHorizontalLine,
    MonthDayYearSlash,
    MonthDayYearPoint,
    //天开始
    Day,
    DayMonth,
    DayMonthHorizontalLine,
    DayMonthSlash,
    DayMonthPoint,
    DayMonthYear,
    DayMonthYearHorizontalLine,
    DayMonthYearSlash,
    DayMonthYearPoint,
    //时间未写
}DateFormatType;

@interface JFUtil : NSObject

/**
 *  隐藏空白cell得横线
 *
 *  @param tableView 操作表
 */
+ (void)setExtraCellLineHidden:(UITableView *)tableView;
/**
 *  弹出提醒Label
 *
 *  @param view  所属视图
 *  @param text  提示文本
 *  @param delay 倒计时移除
 */
+ (void)showMBAlertLabel:(UIView*)view text:(NSString*)text afterDelay:(NSTimeInterval)delay;
/**
 *  设置Textfield文本
 *
 *  @param textField      设置对象
 *  @param textFieldColor 文本颜色
 *  @param placehoderStr  提醒文本
 */
+ (void)setTextFieldCustom:(UITextField*)textField textColor:(UIColor*)textFieldColor placehoder:(NSString*)placehoderStr;
/**
 *  设置textfield提醒文本颜色
 *
 *  @param textField 设置对象
 *  @param phcolor   设置颜色
 */
+ (void)setTextFieldPlacehoderColor:(UITextField*)textField placeHoderColor:(UIColor*)phcolor;
/**
 *  设置导航条样式
 *
 *  @param navigationController 设置对象
 *  @param titleColor           标题颜色
 *  @param titlefont            标题字体
 */
+ (void)setNavigationTitleStyle:(UINavigationController *)navigationController titleColor:(UIColor*)titleColor titleFont:(UIFont*)titleFont;
/**
 *  设置导航条样式
 *
 *  @param navigationController 设置对象
 *  @param value                系统透明设置
 *  @param tintColor            tintColor
 *  @param titleColor           标题颜色
 *  @param titlefont            标题字体
 */
+ (void)setNavigationControllerStyle:(UINavigationController *)navigationController translucent:(BOOL)value tintColor:(UIColor*)tintColor titleColor:(UIColor*)titleColor titleFont:(UIFont*)titlefont;
/**
 *  设置全局导航统一样式
 *
 *  @param barTintColor    bar颜色
 *  @param tintColor       颜色
 *  @param backgroundColor 背景色
 *  @param translucent     是否透明
 */
+ (void)setNavigationAppearance:(UIColor*)barTintColor tintColor:(UIColor*)tintColor backgroundColor:(UIColor*)backgroundColor;
/**
 *  设置全局navigation返回文本显示
 *
 *  @param ishidden 是否隐藏
 */
+ (void)hideBackTitle:(BOOL)ishidden;
/**
 *  设置全局navigation返回图片
 *
 *  @param image 返回图片
 */
+ (void)setNavigationAppearanceBackImage:(UIImage *)image;
/**
 *  设置navigation得下面横线
 *
 *  @param lineColor 颜色
 */
+ (void)setNavigationAppearanceShadowColorImage:(UIColor *)lineColor;
/**
 *  颜色转image
 *
 *  @param color 颜色
 *  @param size  大小
 *
 *  @return image
 */
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size;
#pragma mark 验证
/**
 *  验证是否为数字号码
 *
 *  @param number 验证对象
 *
 *  @return 返回bool
 */
+ (BOOL)validateNumber:(NSString*)number;
/**
 *  验证是否为邮箱
 *
 *  @param number 验证对象
 *
 *  @return 返回bool
 */
+ (BOOL)validateEmail:(NSString *)email;

#pragma mark 字符串操作
/**
 *  去除字符串首尾的空格
 *
 *  @param value 操作对象
 *
 *  @return 字符串对象
 */
+ (NSString *)removeLeadingAndTrailingSpaces:(NSString *)value;
/**
 *  去除字符串所有空格
 *
 *  @param value 操作对象
 *
 *  @return 字符串对象
 */
+ (NSString *)replaceBlankSpace:(NSString *)value;
/**
 *  替换号码得部分字符：@"-",@"+86",@"+1",@"＋",@"(",@")", @" ",@" ",@""
 *
 *  @param value 操作对象
 *
 *  @return 字符串对象
 */
+ (NSString *)replacePhoneNumber:(NSString *)value;
/**
 *  替换字符串
 *
 *  @param value   操作对象
 *  @param reValue 需要替换得字符
 *  @param withStr 替换字符
 *
 *  @return 字符串对象
 */
+ (NSString *)replaceString:(NSString *)value replaceArray:(NSArray *)reValue replaceValue:(NSString *)withStr;
#pragma mark 时间格式化
/**
 *  格式化日期
 *
 *  @param date 日期
 *  @param type 格式化返回格式
 *
 *  @return 字符串
 */
+ (NSString *)dateFormatToString:(NSDate *)date formatType:(DateFormatType)type;
/**
 *  格式化时间
 *
 *  @param timeStamp 秒
 *  @param type      格式化返回格式
 *
 *  @return 字符串
 */
+ (NSString *)dateFormatToStringFromTimeStamp:(NSInteger)timeStamp formatType:(DateFormatType)type;
/**
 *  计算字符串得size
 *
 *  @param value   字符串值
 *  @param font    字体
 *  @param maxSize 最大size
 *
 *  @return 字符串size
 */
+ (CGSize)sizeWithString:(NSString *)value font:(UIFont *)font maxSize:(CGSize)maxSize;

@end

/**
 *  自定义全局使用颜色
 */
@interface UIColor (CustomColor)
/*
 * Put the string color into UIColor, #5F9C74, for example
 * Param stringToConvert #5F9C74
 */
+ (UIColor *) colorWithHexString: (NSString *) stringToConvert;
/*
 * Put the string color and alpha into UIColor, #5F9C74, for example
 * Param stringToConvert #5F9C74
 */
+ (UIColor *) colorAlphaWithHexString: (NSString *) stringToConvert alpha:(CGFloat)alpha;
/*
 * Simplify the original method
 */
+ (UIColor *)colorWithRed:(NSUInteger)red
                    green:(NSUInteger)green
                     blue:(NSUInteger)blue;


/*
 * Custom Color
 */
+ (UIColor *)customGrayColor;
+ (UIColor *)customRedColor;
+ (UIColor *)customYellowColor;
+ (UIColor *)customGreenColor;
+ (UIColor *)customBlueColor;
+ (UIColor *)customControllerBackgroundColor;
+ (UIColor *)customControllerBackgroundColorAlpha;
/*
 * Global or System Color
 */
+ (UIColor *)customSystemColor;
+ (UIColor *)customDarkPlaceColor;
+ (UIColor *)customLightPlaceColor;
@end

